package mmc.util;

import java.io.IOException;
import java.io.OutputStream;

public class ThroughputMeterDebugOutputStream extends OutputStream{

	private OutputStream inner;
	private APSCounter throughputMeter;
	
	public ThroughputMeterDebugOutputStream(APSCounter throughputMeter, OutputStream inner) {
		this.inner = inner;
		this.throughputMeter = throughputMeter;
	}

	@Override
	public void close() throws IOException {
		inner.close();
	}

	@Override
	public void flush() throws IOException {
		inner.flush();
	}

	@Override
	public void write(byte[] b, int off, int len) throws IOException {
		throughputMeter.notify(0, len);
		inner.write(b, off, len);
	}

	@Override
	public void write(byte[] b) throws IOException {
		throughputMeter.notify(0, b.length);
		inner.write(b);
	}

	@Override
	public void write(int b) throws IOException {
		throughputMeter.notify(0, 1);
		inner.write(b);
	}
}
